<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>用户列表</title>

    <link rel="stylesheet" type="text/css" href="/static/Admin/plugins/colorpicker/colorpicker.css" media="screen">
    <link rel="stylesheet" type="text/css" href="/static/Admin/custom-plugins/wizard/wizard.css" media="screen">

    <!-- Required Stylesheets -->
    <link rel="stylesheet" type="text/css" href="/static/Admin/bootstrap/css/bootstrap.min.css" media="screen">
    <link rel="stylesheet" type="text/css" href="/static/Admin/css/fonts/ptsans/stylesheet.css" media="screen">
    <link rel="stylesheet" type="text/css" href="/static/Admin/css/fonts/icomoon/style.css" media="screen">

    <link rel="stylesheet" type="text/css" href="/static/Admin/css/mws-style.css" media="screen">
    <link rel="stylesheet" type="text/css" href="/static/Admin/css/icons/icol16.css" media="screen">
    <link rel="stylesheet" type="text/css" href="/static/Admin/css/icons/icol32.css" media="screen">

    <!-- Demo Stylesheet -->
    <link rel="stylesheet" type="text/css" href="/static/Admin/css/demo.css" media="screen">

    <!-- jQuery-UI Stylesheet -->
    <link rel="stylesheet" type="text/css" href="/static/Admin/jui/css/jquery.ui.all.css" media="screen">
    <link rel="stylesheet" type="text/css" href="/static/Admin/jui/jquery-ui.custom.css" media="screen">

    <!-- Theme Stylesheet -->
    <link rel="stylesheet" type="text/css" href="/static/Admin/css/mws-theme.css" media="screen">
    <link rel="stylesheet" type="text/css" href="/static/Admin/css/themer.css" media="screen">

    <!-- 引入 layui -->
    <script src="/static/layui/layui.all.js"></script>
    <link rel="stylesheet" href="/static/layui/css/layui.css">

</head>

<body>

    <div class="mws-panel grid_8">
        <div class="mws-panel-header" style="height: 49px">
            <span>
                <i class="icon-table"></i> 客户列表</span>
        </div>
        <div class="mws-panel-body no-padding">
            <div id="DataTables_Table_1_wrapper" class="dataTables_wrapper" role="grid">
                <!--
                <div id="DataTables_Table_1_length" class="dataTables_length">
                    <a href="/user/Excel" class="btn btn-info" id="excel">导出为Excel文件</a>
                </div>
              -->
                <form action="/user/UserList" method="get">

                    
                    
                    <div class="dataTables_filter" id="DataTables_Table_1_filter">
                        <label>手机号、用户名:
                            <input type="text" aria-controls="DataTables_Table_1" name="keyword" value="{$keyword}">
                            <input type="submit" class="btn btn-info">
                        </label>
                    </div>
                </form>

                <table class="mws-datatable-fn mws-table dataTable" id="DataTables_Table_1" aria-describedby="DataTables_Table_1_info">
                    <thead>
                        <tr role="row">
                            <th class="" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" style="width:5%;" aria-sort="ascending"
                                aria-label="Rendering engine: activate to sort column ascending">编号</th>
                            <th class="" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" style="width: 5%;" aria-label="Browser: activate to sort column ascending">用户名</th>
                            <th class="" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" style="width: 5%;" aria-label="Platform(s): activate to sort column ascending">手机号</th>
                            <th class="" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" style="width: 10%;" aria-label="Platform(s): activate to sort column ascending">注册时间</th>
                            <th class="" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" style="width: 5%;" aria-label="Platform(s): activate to sort column ascending">身份类别</th>
                            <th class="" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" style="width: 30%;" aria-label="Platform(s): activate to sort column ascending">地址</th>
                            <th class="" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" style="width: 5%" aria-label="Platform(s): activate to sort column ascending">可用积分数</th>
                            <th class="" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" style="width: 5%" aria-label="Platform(s): activate to sort column ascending">消费积分数</th>
                            <th class="" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" style="width: 5%" aria-label="Platform(s): activate to sort column ascending">邀请码</th>

                            <!--
                            <th class="" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" style="width: 368px;" aria-label="Platform(s): activate to sort column ascending">
                                <select name="user_status" id="js_isdel">
                                    <option value="">--用户状态--</option>
                                    <option value="0">正常用户</option>
                                    <option value="1">黑名单用户</option>
                                </select>
                            </th>
                            -->
                            <th class="" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" style="width: 5%;" aria-label="Platform(s): activate to sort column ascending">操作</th>
                        </tr>
                    </thead>

                    <tbody>
                        {foreach name="list" item="vo"}
                        {php} $vo=\app\admin\model\UserModel::handleUserInfo($vo);{/php}
                        <tr class="gradeA odd">
                            <td class="">{$vo.user_id}</td>
                            <td class="">{$vo.user_name}</td>
                            <td class="">{$vo.user_phone}</td>
                            <td class="">{$vo.register_time}</td>
                            <td class="">{switch name="vo.user_type"}
                                {case value="1"}设计院{/case}
                                {case value="2"}直接甲方{/case}
                                {case value="3"}代理商{/case}
                            {/switch}
                            </td>
                            <td class="">{$vo.address}</td>
                            <td class="">{$vo.available_points}</td>
                            <td class="">{$vo.consume_points}</td>
                            <td class="">{$vo.user_invite_code}</td>
                            <!--
                            <td class="" >
                                {switch name="$vo.is_del"} {case value="0"} <span style="color:green">正常用户</span> {/case} {case value="1"} <span style="color:red">黑名单用户</span> {/case}  {/switch}
                            </td>
                            -->
                            <td>
                                {switch name="$vo.is_del"} 
                                {case value = '0'} 
                                <a href="javascript:;" class="btn btn-danger changeStatus " value="1" name="{$vo.user_id}">将客户禁用</a>
                                {/case} 
                                {case value = '1'}
                                <a href="javascript:;" class="btn btn-success changeStatus" value="0" name="{$vo.user_id}">从黑名单中恢复</a>
                                {/case}
                                {/switch}
                                {empty name="vo.user_invite_code"}
                                 <a href="javascript:;" class="btn btn-success js_generate_invite" value="0" name="{$vo.user_id}">生成邀请码</a>
                                {else}
                                <a href="javascript:;" class="btn btn-success js_generate_invite" value="0" name="{$vo.user_id}">删除邀请码</a>

                                {/empty}
                            </td>
                        </tr>
                        {/foreach}
                    </tbody>
                </table>
                <div class="" id="DataTables_Table_1_paginate" style="text-align: center">
                    {$list->render()}
                </div>
            </div>
        </div>
    </div>




</body>
<!-- JavaScript Plugins -->
<script src="/static/Admin/js/libs/jquery-1.8.3.min.js"></script>
<script src="/static/Admin/js/libs/jquery.mousewheel.min.js"></script>
<script src="/static/Admin/js/libs/jquery.placeholder.min.js"></script>
<script src="/static/Admin/custom-plugins/fileinput.js"></script>

<!-- jQuery-UI Dependent Scripts -->
<script src="/static/Admin/jui/js/jquery-ui-1.9.2.min.js"></script>
<script src="/static/Admin/jui/jquery-ui.custom.min.js"></script>
<script src="/static/Admin/jui/js/jquery.ui.touch-punch.js"></script>

<!-- Plugin Scripts -->
<script src="/static/Admin/plugins/datatables/jquery.dataTables.min.js"></script>
<!--[if lt IE 9]>
        <script src="js/libs/excanvas.min.js"></script>
        <![endif]-->
<script src="/static/Admin/plugins/flot/jquery.flot.min.js"></script>
<script src="/static/Admin/plugins/flot/plugins/jquery.flot.tooltip.min.js"></script>
<script src="/static/Admin/plugins/flot/plugins/jquery.flot.pie.min.js"></script>
<script src="/static/Admin/plugins/flot/plugins/jquery.flot.stack.min.js"></script>
<script src="/static/Admin/plugins/flot/plugins/jquery.flot.resize.min.js"></script>
<script src="/static/Admin/plugins/colorpicker/colorpicker-min.js"></script>
<script src="/static/Admin/plugins/validate/jquery.validate-min.js"></script>
<script src="/static/Admin/custom-plugins/wizard/wizard.min.js"></script>

<!-- Core Script -->
<script src="/static/Admin/bootstrap/js/bootstrap.min.js"></script>
<script src="/static/Admin/js/core/mws.js"></script>

<!-- Themer Script (Remove if not needed) -->
<script src="/static/Admin/js/core/themer.js"></script>

<!-- Demo Scripts (remove if not needed) -->
<script src="/static/Admin/js/demo/demo.dashboard.js"></script>


<script>
        var args = {
            user_status: "{$user_status}",
        };

        var keyword = "{$keyword}";
        if ( keyword.length > 0) {
            
            args.keyword = keyword;

        }
        function generateArgsStr() {
            var str = ""
            for (var name in args) {
                if (str.length == 0) {
                    str = name + "/" + args[name];
                } else {
                    str += "/" + name + "/" + args[name];
                }
            }
            return str;
        }
        var url = '__WebSite__/user/UserList';

        $("#js_isdel option[value=" + args.user_status + "]").prop("selected", "selected");

        $("#js_isdel").on('change',function () {
            var val = $(this).val();
            args.user_status = val;
            url += "/" + generateArgsStr();
            location.href = url;
        })
</script>

<script>
    // ajax 状态修改
        $('.changeStatus').on('click', function () {
            var res = window.confirm('确定执行此项操作');
            if(res){
                var id = $(this).attr('name');
                var status = $(this).attr('value');
                console.log(id);
                console.log(status);
                me=$(this);
                $.ajax({
                    url: '/user/AjaxChangeStatus',
                    type: 'post',
                    data: { 'id': id, 'status': status },
                    success: function (data) {

                        console.log(data);
                        if (data == 1) {
                            alert('修改成功');

                            if(status == 1){

                                me.parent('td').prev().html('<span style="color:red">黑名单用户</span>');
                                
                                me.removeClass('btn-danger').addClass('btn-success').attr('value',0).html('从黑名单中恢复');

                            }else{
                                me.parent('td').prev().html('<span style="color:green">正常用户</span>');
                                
                                me.removeClass('btn-success').addClass('btn-danger').attr('value', 1).html('将客户禁用');
                            }
                        } else {
                            alert('操作失败');
                        }
                    }
                })
            }
        });
    $(".js_generate_invite").click(function () {
        var id = $(this).attr('name');

       $.post('/user/AjaxUpdateInviteCode',{id:id},function (data) {

           if(data)
           {
               location.reload();
           }else{
               alert("操作失败");
           }
       },'json')
    });
</script>


</html>